Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build: Replace global with globalThis [WIP] #19386

Closed
wants to merge 19 commits into from
Closed

Build: Replace global with globalThis [WIP] #19386

wants to merge 19 commits into from

Conversation

IanVS
Copy link
Member

@IanVS IanVS commented Oct 7, 2022

Issue:

What I did

This removes the use of the global npm package, instead preferring globalThis, which works in all supported storybook environments. Besides removing an extra (and widespread) dependency, this also improves our typescript coverage, since global did not have type definitions, but globalThis does. I also used module augmentation to add the types for the global values that storybook adds as well.

The reason this is still WIP is that mocking globalThis in tests only works in jest 28+, so now that we've updated I can start working on the tests.

There are also some type errors that I could use some help with. Some of them are new and result from having proper types for globalThis, and some are perhaps due to faulty types in globalThis.d.ts.

How to test

  • Is this testable with Jest or Chromatic screenshots?
  • Does this need a new example in the kitchen sink apps?
  • Does this need an update to the documentation?

If your answer is yes to any of these, please make sure to include it in your PR.

# Conflicts:
#	code/addons/backgrounds/package.json
#	code/addons/highlight/package.json
#	code/addons/interactions/package.json
#	code/addons/jest/package.json
#	code/addons/links/package.json
#	code/addons/measure/package.json
#	code/addons/storyshots/storyshots-core/src/api/index.ts
#	code/addons/viewport/package.json
#	code/examples/cra-ts-kitchen-sink/package.json
#	code/frameworks/ember/package.json
#	code/frameworks/react-vite/package.json
#	code/frameworks/vue3-vite/package.json
#	code/lib/addons/package.json
#	code/lib/addons/src/main.ts
#	code/lib/channel-postmessage/package.json
#	code/lib/channel-websocket/package.json
#	code/lib/core-client/package.json
#	code/lib/core-client/src/globals/globals.ts
#	code/lib/core-client/src/preview/start.ts
#	code/lib/instrumenter/package.json
#	code/lib/ui/src/components/sidebar/Search.tsx
#	code/lib/ui/src/index.tsx
#	code/renderers/html/package.json
#	code/renderers/preact/package.json
#	code/renderers/server/package.json
#	code/renderers/svelte/package.json
#	code/renderers/vue/package.json
#	code/renderers/vue/src/globals.ts
#	code/renderers/vue3/package.json
#	code/renderers/vue3/src/globals.ts
#	code/renderers/web-components/package.json
#	code/renderers/web-components/src/index.ts
#	code/yarn.lock
IanVS added 16 commits November 16, 2022 22:25
# Conflicts:
#	code/addons/actions/src/runtime/withActions.ts
#	code/addons/actions/template/stories/parameters.stories.ts
#	code/addons/backgrounds/package.json
#	code/addons/controls/template/stories/basics.stories.ts
#	code/addons/controls/template/stories/conditional.stories.ts
#	code/addons/controls/template/stories/disable.stories.ts
#	code/addons/controls/template/stories/filters.stories.ts
#	code/addons/controls/template/stories/issues.stories.ts
#	code/addons/controls/template/stories/matchers.stories.ts
#	code/addons/controls/template/stories/sorting.stories.ts
#	code/addons/docs/package.json
#	code/addons/docs/src/preset.ts
#	code/addons/docs/src/typings.d.ts
#	code/addons/highlight/package.json
#	code/addons/interactions/package.json
#	code/addons/interactions/template/stories/basics.stories.ts
#	code/addons/jest/package.json
#	code/addons/links/package.json
#	code/addons/measure/package.json
#	code/addons/outline/package.json
#	code/addons/storyshots/storyshots-core/package.json
#	code/addons/storyshots/storyshots-core/src/frameworks/configure.ts
#	code/addons/storyshots/storyshots-core/src/frameworks/svelte/renderTree.ts
#	code/addons/toolbars/template/stories/globals.stories.ts
#	code/addons/viewport/package.json
#	code/examples/angular-cli/package.json
#	code/examples/angular-cli/src/cssWarning.ts
#	code/examples/html-kitchen-sink/package.json
#	code/examples/html-kitchen-sink/stories/button.stories.js
#	code/examples/html-kitchen-sink/stories/from-essentials/Header.ts
#	code/examples/html-kitchen-sink/stories/from-essentials/Page.ts
#	code/examples/html-kitchen-sink/typings.d.ts
#	code/examples/official-storybook/head-warning.js
#	code/examples/official-storybook/package.json
#	code/examples/preact-kitchen-sink/package.json
#	code/examples/react-ts/.storybook/main.ts
#	code/examples/react-ts/src/button.tsx
#	code/examples/svelte-kitchen-sink/package.json
#	code/examples/svelte-kitchen-sink/src/components/Button.test.js
#	code/examples/web-components-kitchen-sink/package.json
#	code/frameworks/angular/package.json
#	code/frameworks/angular/setup-jest.ts
#	code/frameworks/angular/src/client/angular/helpers.ts
#	code/frameworks/angular/src/typings.d.ts
#	code/frameworks/ember/package.json
#	code/frameworks/ember/src/client/preview/render.ts
#	code/frameworks/html-webpack5/package.json
#	code/frameworks/nextjs/template/cli/ts/Button.tsx
#	code/frameworks/react-webpack5/src/typings.d.ts
#	code/frameworks/vue-webpack5/src/typings.d.ts
#	code/lib/addons/package.json
#	code/lib/addons/src/hooks.ts
#	code/lib/addons/src/main.ts
#	code/lib/api/src/lib/shortcut.ts
#	code/lib/api/src/lib/stories.ts
#	code/lib/api/src/modules/refs.ts
#	code/lib/api/src/modules/release-notes.ts
#	code/lib/api/src/modules/shortcuts.ts
#	code/lib/api/src/modules/url.ts
#	code/lib/api/src/modules/versions.ts
#	code/lib/api/src/tests/shortcut.test.js
#	code/lib/api/src/tests/stories.test.ts
#	code/lib/channel-postmessage/package.json
#	code/lib/channel-websocket/package.json
#	code/lib/client-api/src/ClientApi.ts
#	code/lib/client-api/src/StoryStoreFacade.ts
#	code/lib/client-api/src/queryparams.ts
#	code/lib/core-client/package.json
#	code/lib/core-client/src/manager/index.ts
#	code/lib/core-client/src/manager/provider.ts
#	code/lib/core-client/src/start.ts
#	code/lib/core-client/src/typings.d.ts
#	code/lib/core-server/src/typings.d.ts
#	code/lib/instrumenter/package.json
#	code/lib/preview-web/src/Preview.tsx
#	code/lib/preview-web/src/PreviewWeb.tsx
#	code/lib/preview-web/src/UrlStore.ts
#	code/lib/preview-web/src/render/StoryRender.ts
#	code/lib/router/src/router.tsx
#	code/lib/store/src/csf/prepareStory.ts
#	code/lib/store/template/stories/argTypes.stories.ts
#	code/lib/store/template/stories/args.stories.ts
#	code/lib/store/template/stories/decorators.stories.ts
#	code/lib/store/template/stories/globals.stories.ts
#	code/lib/store/template/stories/hooks.stories.ts
#	code/lib/store/template/stories/loaders.stories.ts
#	code/lib/store/template/stories/parameters.stories.ts
#	code/lib/store/template/stories/rendering.stories.ts
#	code/lib/theming/src/typings.d.ts
#	code/lib/ui/src/components/sidebar/Search.tsx
#	code/presets/react-webpack/src/typings.d.ts
#	code/presets/server-webpack/package.json
#	code/renderers/html/package.json
#	code/renderers/preact/package.json
#	code/renderers/react/src/render.tsx
#	code/renderers/server/package.json
#	code/renderers/svelte/package.json
#	code/renderers/svelte/src/globals.ts
#	code/renderers/svelte/src/render.ts
#	code/renderers/vue/package.json
#	code/renderers/vue/template/components/index.js
#	code/renderers/vue3/package.json
#	code/renderers/web-components/package.json
#	code/renderers/web-components/src/docs/__testfixtures__/lit-element-demo-card/input.js
#	code/renderers/web-components/src/globals.ts
#	code/renderers/web-components/src/index.ts
#	code/renderers/web-components/src/render.ts
#	code/renderers/web-components/template/components/index.js
#	code/ui/blocks/src/blocks/DocsContainer.tsx
#	code/ui/blocks/src/blocks/DocsContext.ts
#	code/ui/blocks/src/components/Preview.stories.tsx
#	code/ui/blocks/src/components/Story.tsx
#	code/ui/blocks/src/typings.d.ts
#	code/ui/manager/src/components/layout/app.mockdata.tsx
#	code/ui/manager/src/components/sidebar/RefBlocks.tsx
#	code/ui/manager/src/components/sidebar/RefIndicator.tsx
#	code/ui/manager/src/components/sidebar/SearchResults.tsx
#	code/ui/manager/src/components/sidebar/useHighlighted.ts
#	code/ui/manager/src/components/sidebar/utils.ts
#	code/ui/manager/src/index.tsx
#	code/ui/manager/src/runtime.ts
#	code/ui/manager/src/settings/index.tsx
#	code/yarn.lock
#	scripts/.eslintrc.js
We were getting an old version via @types/webpack-virtual-modules
# Conflicts:
#	code/addons/backgrounds/package.json
#	code/addons/highlight/package.json
#	code/addons/interactions/package.json
#	code/addons/jest/package.json
#	code/addons/links/package.json
#	code/addons/measure/package.json
#	code/addons/outline/package.json
#	code/addons/viewport/package.json
#	code/frameworks/ember/package.json
#	code/frameworks/html-webpack5/package.json
#	code/lib/addons/package.json
#	code/lib/channel-postmessage/package.json
#	code/lib/channel-websocket/package.json
#	code/lib/core-client/package.json
#	code/lib/instrumenter/package.json
#	code/package.json
#	code/presets/server-webpack/package.json
#	code/renderers/html/package.json
#	code/renderers/preact/package.json
#	code/renderers/server/package.json
#	code/renderers/svelte/package.json
#	code/renderers/vue/package.json
#	code/renderers/vue3/package.json
#	code/renderers/web-components/package.json
#	code/yarn.lock
# Conflicts:
#	code/addons/a11y/src/a11yRunner.ts
#	code/addons/actions/src/decorator.ts
#	code/addons/backgrounds/package.json
#	code/addons/highlight/package.json
#	code/addons/highlight/src/preview.ts
#	code/addons/interactions/package.json
#	code/addons/jest/package.json
#	code/addons/links/package.json
#	code/addons/links/src/utils.ts
#	code/addons/measure/package.json
#	code/addons/outline/package.json
#	code/addons/storyshots/storyshots-core/src/api/index.ts
#	code/addons/viewport/package.json
#	code/frameworks/ember/package.json
#	code/frameworks/html-webpack5/package.json
#	code/lib/addons/package.json
#	code/lib/addons/src/typings.d.ts
#	code/lib/builder-webpack5/package.json
#	code/lib/builder-webpack5/templates/virtualModuleModernEntry.js.handlebars
#	code/lib/channel-postmessage/package.json
#	code/lib/channel-websocket/package.json
#	code/lib/client-api/package.json
#	code/lib/core-client/package.json
#	code/lib/instrumenter/package.json
#	code/lib/manager-api/src/lib/addons.ts
#	code/lib/manager-api/src/tests/stories.test.ts
#	code/lib/preview-api/src/modules/client-api/StoryStoreFacade.ts
#	code/lib/preview-api/src/modules/client-api/typings.d.ts
#	code/lib/preview-api/src/modules/core-client/start.ts
#	code/lib/preview-api/src/modules/preview-web/Preview.tsx
#	code/lib/preview-api/src/modules/preview-web/WebView.ts
#	code/lib/preview-api/src/modules/preview-web/simulate-pageload.test.ts
#	code/lib/preview-api/src/modules/store/typings.d.ts
#	code/lib/preview-web/package.json
#	code/lib/router/src/router.tsx
#	code/lib/store/package.json
#	code/presets/server-webpack/package.json
#	code/renderers/html/package.json
#	code/renderers/html/src/globals.ts
#	code/renderers/preact/package.json
#	code/renderers/server/package.json
#	code/renderers/svelte/package.json
#	code/renderers/vue/package.json
#	code/renderers/vue3/package.json
#	code/renderers/web-components/package.json
#	code/ui/.storybook/preview.tsx
#	code/ui/components/src/Loader/Loader.tsx
#	code/yarn.lock
@@ -333,7 +334,8 @@ export class Instrumenter {
// returns the original result.
track(method: string, fn: Function, args: any[], options: Options) {
const storyId: StoryId =
args?.[0]?.__storyId__ || global.window.__STORYBOOK_PREVIEW__?.urlStore?.selection?.storyId;
args?.[0]?.__storyId__ ||
globalThis.__STORYBOOK_PREVIEW__?.selectionStore?.selection?.storyId;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ndelangen this could be causing the issue I identified in discord.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant